﻿using Confluent.Kafka.Serialization;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace log4net.extension.kafka
{
    public class LogEntityDeserializer : IDeserializer<Log4netLogEntity>
    {
        public Log4netLogEntity Deserialize(byte[] data)
        {
            if (data == null)
                return null;

            using (MemoryStream ms = new MemoryStream(data))
            {
                ms.Position = 0;
                BinaryFormatter formatter = new BinaryFormatter();
                return formatter.Deserialize(ms) as Log4netLogEntity;
            }
        }
    }
}
